package com.ygqh.baby.model;

import com.mumu.commons.utils.StringUtils;
import com.ygqh.baby.ao.Message;
import com.ygqh.baby.utils.DateConvertUtils;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

/**
 * @author: sunshuo
 * @date: 2018/12/25 14:32
 */
public class YgVote {

	private String voteBatchCode;

	private String title;

	private Date registerStartDate;

	private Date registerEndDate;

	private Date voteStartDate;

	private Date voteEndDate;

	private YgVoteRule voteRule;

	private String couponIdByHelpSuccessForNewUser;

	private String couponIdByHelpSuccessForOldUser;

	private Long couponCountByGift;

	private Date createTime;

	private String createBy;

	private Date updateTime;

	private String updateBy;

	public String getVoteBatchCode() {
		return voteBatchCode;
	}

	public void setVoteBatchCode(String voteBatchCode) {
		this.voteBatchCode = voteBatchCode;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public Date getRegisterStartDate() {
		return registerStartDate;
	}

	public void setRegisterStartDate(Date registerStartDate) {
		this.registerStartDate = registerStartDate;
	}

	public Date getRegisterEndDate() {
		return registerEndDate;
	}

	public void setRegisterEndDate(Date registerEndDate) {
		this.registerEndDate = registerEndDate;
	}

	public Date getVoteStartDate() {
		return voteStartDate;
	}

	public void setVoteStartDate(Date voteStartDate) {
		this.voteStartDate = voteStartDate;
	}

	public Date getVoteEndDate() {
		return voteEndDate;
	}

	public void setVoteEndDate(Date voteEndDate) {
		this.voteEndDate = voteEndDate;
	}

	public YgVoteRule getVoteRule() {
		return voteRule;
	}

	public void setVoteRule(YgVoteRule voteRule) {
		this.voteRule = voteRule;
	}

	public Message validateRegisterDate() {
		Date today = DateConvertUtils.getDateStart(new Date());
		if (registerStartDate != null && today.before(registerStartDate)) {
			return Message.error("活动报名未开始", null);
		}
		if (registerEndDate != null && today.after(registerEndDate)) {
			return Message.error("活动报名已结束", null);
		}
		return Message.success(null);
	}

	public Message validateVoteDate() {
		Date today = DateConvertUtils.getDateStart(new Date());
		if (voteStartDate != null && today.before(voteStartDate)) {
			return Message.error("活动投票未开始", null);
		}
		if (voteEndDate != null && today.after(voteEndDate)) {
			return Message.error("活动投票已结束", null);
		}
		return Message.success(null);
	}

	public String getCouponIdByHelpSuccessForNewUser() {
		return couponIdByHelpSuccessForNewUser;
	}

	public void setCouponIdByHelpSuccessForNewUser(String couponIdByHelpSuccessForNewUser) {
		this.couponIdByHelpSuccessForNewUser = couponIdByHelpSuccessForNewUser;
	}

	public String getCouponIdByHelpSuccessForOldUser() {
		return couponIdByHelpSuccessForOldUser;
	}

	public void setCouponIdByHelpSuccessForOldUser(String couponIdByHelpSuccessForOldUser) {
		this.couponIdByHelpSuccessForOldUser = couponIdByHelpSuccessForOldUser;
	}

	public Long getCouponCountByGift() {
		return couponCountByGift;
	}

	public void setCouponCountByGift(Long couponCountByGift) {
		this.couponCountByGift = couponCountByGift;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public String getCreateBy() {
		return createBy;
	}

	public void setCreateBy(String createBy) {
		this.createBy = createBy;
	}

	public Date getUpdateTime() {
		return updateTime;
	}

	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}

	public String getUpdateBy() {
		return updateBy;
	}

	public void setUpdateBy(String updateBy) {
		this.updateBy = updateBy;
	}

	public Long[] getCouponIds() {
		Set<Long> couponIds = new HashSet<>();
		if (StringUtils.isNotBlank(couponIdByHelpSuccessForNewUser)) {
			for (String id : couponIdByHelpSuccessForNewUser.split(",")) {
				if (StringUtils.isNotBlank(id)) {
					couponIds.add(Long.valueOf(id.trim()));
				}
			}
		}
		if (StringUtils.isNotBlank(couponIdByHelpSuccessForOldUser)) {
			for (String id : couponIdByHelpSuccessForOldUser.split(",")) {
				if (StringUtils.isNotBlank(id)) {
					couponIds.add(Long.valueOf(id.trim()));
				}
			}
		}
		return couponIds.toArray(new Long[0]);
	}
}
